ARD2  1.00 for Rev B. Hardware
Airbag Reference Demonstrator using MPC5604P
freemaster_tsa.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 *
00003 * Freescale Semiconductor Inc.
00004 * (c) Copyright 2004-2010 Freescale Semiconductor
00005 * ALL RIGHTS RESERVED.
00006 *
00007 ****************************************************************************/
00019 #ifndef __FREEMASTER_TSA_H
00020 #define __FREEMASTER_TSA_H
00021 
00022 #include "freemaster_defcfg.h"
00023 
00024 /*****************************************************************************
00025  Target-side Address translation structures and macros
00026 ******************************************************************************/
00027 
00028 /* current TSA version  */
00029 #define FMSTR_TSA_VERSION 2U
00030 
00031 /* TSA flags carried in TSA_ENTRY.info (except the first entry in table) */
00032 #define FMSTR_TSA_INFO_ENTRYTYPE_MASK 0x0003U    /* flags reserved for TSA_ENTRY use */
00033 #define FMSTR_TSA_INFO_STRUCT         0x0000U    /* ENTRYTYPE: structure parent type */
00034 #define FMSTR_TSA_INFO_RO_VAR         0x0001U    /* ENTRYTYPE: read-only variable */
00035 #define FMSTR_TSA_INFO_MEMBER         0x0002U    /* ENTRYTYPE: structure member */
00036 #define FMSTR_TSA_INFO_RW_VAR         0x0003U    /* ENTRYTYPE: read-write variable */
00037 #define FMSTR_TSA_INFO_VAR_FLAG       0x0001U    /* ENTRYTYPE: FLAG: any variable */
00038 #define FMSTR_TSA_INFO_RWV_FLAG       0x0002U    /* ENTRYTYPE: FLAG: R/W access */
00039 
00040 /* TSA table index and size (both unsigned, at least 16 bit wide) */
00041 typedef FMSTR_SIZE FMSTR_TSA_TINDEX;
00042 typedef FMSTR_SIZE FMSTR_TSA_TSIZE;
00043 
00044 /* pointer types used in TSA tables can be overridden in freemaster.h */
00045 /* (this is why macros are used instead of typedefs) */
00046 #ifndef FMSTR_TSATBL_STRPTR 
00047 #define FMSTR_TSATBL_STRPTR  const char*
00048 #endif
00049 #ifndef FMSTR_TSATBL_STRPTR_CAST
00050 #define FMSTR_TSATBL_STRPTR_CAST(x) ((FMSTR_TSATBL_STRPTR)(x))
00051 #endif
00052 #ifndef FMSTR_TSATBL_VOIDPTR 
00053 #define FMSTR_TSATBL_VOIDPTR const void*
00054 #endif
00055 #ifndef FMSTR_TSATBL_VOIDPTR_CAST 
00056 #define FMSTR_TSATBL_VOIDPTR_CAST(x) ((FMSTR_TSATBL_VOIDPTR)(x))
00057 #endif
00058 
00059 /* TSA table entry. The unions inside assures variables sized enough to */
00060 /* accommodate both the C-pointer and the user-requested size (FMSTR_ADDR) */
00061 typedef struct
00062 {
00063     union { FMSTR_TSATBL_STRPTR  p; FMSTR_ADDR n; } name;
00064     union { FMSTR_TSATBL_STRPTR  p; FMSTR_ADDR n; } type;
00065     union { FMSTR_TSATBL_VOIDPTR p; FMSTR_ADDR n; } addr;
00066     union { FMSTR_TSATBL_VOIDPTR p; FMSTR_ADDR n; } info;
00067 } FMSTR_TSA_ENTRY;
00068 
00069 /*//////////////////////////////////////////////// */
00070 /* single table-building macros */
00071 
00072 #define FMSTR_TSA_FUNC(id)  FMSTR_TsaGetTable_##id
00073 #define FMSTR_TSA_FUNC_PROTO(id) const FMSTR_TSA_ENTRY* FMSTR_TSA_FUNC(id) (FMSTR_TSA_TSIZE* pTableSize)
00074 
00075 #define FMSTR_TSA_TABLE_BEGIN(id) \
00076     FMSTR_TSA_FUNC_PROTO(id); \
00077     FMSTR_TSA_FUNC_PROTO(id) { \
00078         static FMSTR_TSA_CDECL FMSTR_TSA_ENTRY fmstr_tsatable[] = { 
00079 
00080 /* entry info  */
00081 #define FMSTR_TSA_INFO1(elem, flags) FMSTR_TSATBL_VOIDPTR_CAST(((sizeof(elem))<<2)|(flags))
00082 #define FMSTR_TSA_INFO2(size, flags) FMSTR_TSATBL_VOIDPTR_CAST(((size)<<2)|(flags))
00083 
00084 #define FMSTR_TSA_STRUCT(name)  \
00085     { FMSTR_TSATBL_STRPTR_CAST(#name), FMSTR_TSATBL_STRPTR_CAST(NULL), FMSTR_TSATBL_VOIDPTR_CAST(NULL), FMSTR_TSA_INFO1(name, FMSTR_TSA_INFO_STRUCT) },
00086     
00087 #define FMSTR_TSA_MEMBER(parenttype,name,type) \
00088     { FMSTR_TSATBL_STRPTR_CAST(#name), FMSTR_TSATBL_STRPTR_CAST(type), FMSTR_TSATBL_VOIDPTR_CAST(&((parenttype*)0)->name), FMSTR_TSA_INFO1(((parenttype*)0)->name, FMSTR_TSA_INFO_MEMBER) },
00089     
00090 #define FMSTR_TSA_RO_VAR(name,type) \
00091     { FMSTR_TSATBL_STRPTR_CAST(#name), FMSTR_TSATBL_STRPTR_CAST(type), FMSTR_TSATBL_VOIDPTR_CAST(&(name)), FMSTR_TSA_INFO1(name, FMSTR_TSA_INFO_RO_VAR) },
00092 
00093 #define FMSTR_TSA_RW_VAR(name,type) \
00094     { FMSTR_TSATBL_STRPTR_CAST(#name), FMSTR_TSATBL_STRPTR_CAST(type), FMSTR_TSATBL_VOIDPTR_CAST(&(name)), FMSTR_TSA_INFO1(name, FMSTR_TSA_INFO_RW_VAR) },
00095 
00096 #define FMSTR_TSA_RO_MEM(name,type,addr,size) \
00097     { FMSTR_TSATBL_STRPTR_CAST(#name), FMSTR_TSATBL_STRPTR_CAST(type), FMSTR_TSATBL_VOIDPTR_CAST(addr), FMSTR_TSA_INFO2(size, FMSTR_TSA_INFO_RO_VAR) },
00098 
00099 #define FMSTR_TSA_RW_MEM(name,type,addr,size) \
00100     { FMSTR_TSATBL_STRPTR_CAST(#name), FMSTR_TSATBL_STRPTR_CAST(type), FMSTR_TSATBL_VOIDPTR_CAST(addr), FMSTR_TSA_INFO2(size, FMSTR_TSA_INFO_RW_VAR) },
00101 
00102 #define FMSTR_TSA_TABLE_END() }; \
00103     if(pTableSize) *pTableSize = sizeof(fmstr_tsatable); \
00104     return fmstr_tsatable; }
00105 
00106 /*///////////////////////////////////////////////////////////////////// */
00107 /* TSA "Base Types", all are implemented as a one-char strings */
00108 /* retrieved by PC and parsed according to the binary scheme */
00109 /* "111STTZZ" where TT=type[int,frac,fp,x] S=signed ZZ=size[1,2,4,8] */
00110 
00111 #define FMSTR_TSA_UINT8   "\xE0"
00112 #define FMSTR_TSA_UINT16  "\xE1"
00113 #define FMSTR_TSA_UINT32  "\xE2"
00114 #define FMSTR_TSA_UINT64  "\xE3"
00115 #define FMSTR_TSA_SINT8   "\xF0"
00116 #define FMSTR_TSA_SINT16  "\xF1"
00117 #define FMSTR_TSA_SINT32  "\xF2"
00118 #define FMSTR_TSA_SINT64  "\xF3"
00119 #define FMSTR_TSA_UFRAC16 "\xE5"
00120 #define FMSTR_TSA_UFRAC32 "\xE6"
00121 #define FMSTR_TSA_FRAC16  "\xF5"
00122 #define FMSTR_TSA_FRAC32  "\xF6"
00123 #define FMSTR_TSA_FLOAT   "\xFA"
00124 #define FMSTR_TSA_DOUBLE  "\xFB"
00125 
00126 /* macro used to describe "User Type" */
00127 #define FMSTR_TSA_USERTYPE(type) #type
00128 
00129 /* macro used to describe pure memory space */
00130 #define FMSTR_TSA_MEMORY NULL
00131 
00132 
00133 /*//////////////////////////////////////////////// */
00134 /* master TSA table-retrieval building macros */
00135 
00136 #define FMSTR_TSA_TABLE_LIST_BEGIN() \
00137     const FMSTR_TSA_ENTRY* FMSTR_TsaGetTable(FMSTR_TSA_TINDEX nTableIndex, FMSTR_TSA_TSIZE* pTableSize) {
00138         
00139 #define FMSTR_TSA_TABLE(id) \
00140     if(!nTableIndex--) { \
00141         FMSTR_TSA_FUNC_PROTO(id); \
00142         return FMSTR_TSA_FUNC(id)(pTableSize); \
00143     } else
00144         
00145 #define FMSTR_TSA_TABLE_LIST_END() \
00146     { return NULL; } }
00147 
00148 /*****************************************************************************
00149  Target-side Address translation functions
00150 ******************************************************************************/
00151 
00152 /* master TSA table-retrieval function */
00153 const FMSTR_TSA_ENTRY* FMSTR_TsaGetTable(FMSTR_TSA_TINDEX nTableIndex, FMSTR_TSA_TSIZE* pTableSize);
00154 
00155 #endif /* __FREEMASTER_TSA_H */
00156